<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"   lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>用户管理</title>
        <link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.5.4.5/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.5.4.5/themes/icon.css">
        <script src="/js/jquery-easyui-1.5.4.5/jquery.min.js"></script>
        <script src="/js/jquery-easyui-1.5.4.5/jquery.easyui.min.js"></script>
    </head>

    <body>
	    <table class="easyui-datagrid" title="用户管理" style="width:90%;height:500px" id="table-grid"
			data-options="singleSelect:true,collapsible:false,url:'/userControl/GET/cn.com.fig.dao.UserMapper.list',method:'get',toolbar:toolbar,pagination:true,pageSize:20">
		<thead>
			<tr>
				<th data-options="field:'userId',width:100">用户编号</th>
				<th data-options="field:'userName',width:100">用户名称</th>
				<th data-options="field:'departName',width:100">所属部门</th>
				<th data-options="field:'mobile',width:100">手机号</th>
				<th data-options="field:'phone',width:100">办公电话</th>
				<th data-options="field:'email',width:100">邮箱地址</th>
				<th data-options="field:'homeAddress',width:400">家庭地址</th>
				<th data-options="field:'comAddress',width:400">办公地址</th>
				<th data-options="field:'lockStatus',width:100,formatter: function(value,row,index){
				if(value == '0') return '锁定';
				if(value == '1') return '未锁定';
			}">锁定状态</th>
				<th data-options="field:'userStatus',width:100,formatter: function(value,row,index){
				if(value == '0') return '无效';
				if(value == '1') return '有效';
			}">用户状态</th>
			</tr>
		</thead>
	</table>
	<div id="saveWindows" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:400px;padding:10px;">
		<form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
			<table>
				<tr>
					<td width="80px">用户编号:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="userId" id="userId" data-options="required:true" width='60px'></input>
	    			</td>
				</tr>
				<tr>
					<td>用户名称:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="userName" id="userName" data-options="required:true" width="80px"></input>
	    			</td>
				</tr>
				<tr>
					<td>所属部门:</td>
	    			<td>		    			
						<select id="departId" class="easyui-combobox" name="departId"  style="width:200px;" 
						data-options="
							valueField: 'departId',
						    textField: 'departName',
						    url: '/dictionary/list?dicId=depart',
						    required:true
						">
						</select>
					</td>
				</tr>
				<tr>
					<td>手机号:</td>
	    			<td>		    			
						<input class="easyui-textbox" type="text" name="mobile" id="mobile" data-options="required:true" width="300px"></input>
					</td>
				</tr>
				<tr>
					<td>办公电话:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="phone" id="phone" data-options="required:true" width="300px"></input>
	    			</td>
				</tr>
				<tr>
					<td>邮箱地址:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="email" id="email" data-options="required:true" width="300px"></input>
	    			</td>
				</tr>
				<tr>
					<td>家庭地址:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="homeAddress" id="homeAddress" data-options="required:true" width="500px"></input>
	    			</td>
				</tr>
				<tr>
					<td>办公地址:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="comAddress" id="comAddress" data-options="required:true" width="500px"></input>
	    			</td>
				</tr>
				<tr>
					<td>锁定状态:</td>
	    			<td>		    			
						<select id="lockStatus" class="easyui-combobox" name="lockStatus"  style="width:200px;">
						    <option value="1">未锁定</option>
						    <option value="0">锁定</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>用户状态:</td>
	    			<td>		    			
						<select id="userStatus" class="easyui-combobox" name="userStatus"  style="width:200px;">
						    <option value="1">有效</option>
						    <option value="0">无效</option>
						</select>
						<input id='insertMark' name='insertMark' type='hidden' value='0'>
					</td>
				</tr>
				<tr>
				<td><input type='button' onclick="submitForm();" value='保存'/></td>
				<td><input type='button' onclick="$('#saveWindows').window('close');" value='取消'/></td>
				</tr>
			</table>
		</form>
	</div>
	<!-- 身份信息相关操作 -->
	<div id="identityWindows" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px;height:500px;padding:10px;overflow: hidden;">
		<table class="easyui-datagrid" title="身份管理" style="width:99%;height:400px" id="identity-grid"
			data-options="singleSelect:false,collapsible:false,method:'get',pagination:false,idField:'identityId'">
		<thead>
			<tr>				
				<th data-options="field:'userId',width:60,checkbox:true"></th>
				<th data-options="field:'identityName',width:100">用户身份</th>
				<th data-options="field:'groupName',width:100">所属岗位</th>
				<th data-options="field:'departName',width:100">所属部门</th>
				<th data-options="field:'primaryMark',width:100,formatter: function(value,row,index){
				if(value == '0') return '非主身份';
				if(value == '1') return '主身份';
			}">主身份标志</th>
				<th data-options="field:'identityStatus',width:100,formatter: function(value,row,index){
				if(value == '0') return '无效';
				if(value == '1') return '有效';
			}">身份状态</th>
				<th data-options="field:'mainPage',width:200">首页地址</th>
			</tr>
		</thead>
	</table>
	</div>
	<div id="identitySaveWindows" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px;height:300px;padding:10px;">
		<form id="identityForm" class="easyui-form" method="post" data-options="novalidate:true">
			<table>
				<tr>
					<td width="80px">用户编号:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="userId" id="userId_identity" data-options="readonly:true" width='60px'></input>
	    			</td>
				</tr>
				<tr>
					<td>用户名称:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="userName" id="userName_identity" data-options="readonly:true" width="80px"></input>
	    			</td>
				</tr>
				<tr>
					<td>身份编号:</td>
	    			<td>		    			
						<input class="easyui-textbox" type="text" name="identityId" id="identityId_identity" data-options="readonly:true" width="300px"></input>
					</td>
				</tr>
				<tr>
					<td>身份名称:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" name="identityName" id="identityName_identity" data-options="readonly:true" width="300px"></input>
	    			</td>
				</tr>
				<tr>
					<td>主身份标识:</td>
	    			<td>		    			
						<select id="primaryMark_identity" class="easyui-combobox" name="primaryMark"  style="width:200px;">
						    <option value="1">主身份</option>
						    <option value="0">非主身份</option>
						</select>
						<input id='userIdentiryId_identity' name='userIdentiryId' type='hidden'>
						<input id='insertMark_identity' name='insertMark' type='hidden' value='1'>
					</td>
				</tr>
				<tr>
				<td><input type='button' onclick="identitySubmitForm();" value='保存'/></td>
				<td><input type='button' onclick="$('#identitySaveWindows').window('close');" value='取消'/></td>
				</tr>
			</table>
		</form>
	</div>
  <script type="text/javascript">		
  	var cWindow = false;
	//dataGrid工具栏
	var toolbar = [{
				text:'新增',
				iconCls:'icon-add',
				handler:function(){
					var tt = $('#table-grid');
					var node = tt.datagrid('getSelected');
					var pId = null;
					$('#insertMark').val('1');
					$('#userId').textbox("readonly",false);
					$("#saveWindows").window('open');
				}
			},{
				text:'编辑',
				iconCls:'icon-edit',
				handler:function(){
					var tt = $('#table-grid');
					var row=tt.datagrid('getSelected');
					if(row){
						$("#saveWindows").window('open');
						$('#insertMark').val('0');
						$('#userId').textbox("setValue",row.userId);
						$('#userName').textbox("setValue",row.userName);
						$('#mobile').textbox("setValue",row.mobile);
						$('#phone').textbox("setValue",row.phone);
						$('#email').textbox("setValue",row.email);
						$('#homeAddress').textbox("setValue",row.homeAddress);
						$('#comAddress').textbox("setValue",row.comAddress);
						$('#lockStatus').combobox("select",row.lockStatus);
						$('#userStatus').combobox("select",row.userStatus);
						$('#departId').combobox("select",row.departId);
						$('#userId').textbox("readonly",true);
					}else{
						$.messager.alert('Warning','请选择要编辑的行！');
					}
				}
			},{
				text:'删除',
				iconCls:'icon-remove',
				handler:function(){
							var tt = $('#table-grid');
							var row=tt.datagrid('getSelected');
							if(!row){
								$.messager.alert('Warning','请选择要删除的行！');
							}
					$.messager.confirm('提示','您确定要删除吗？',function (r){
						if(r){
							$.ajax({
								   type: "POST",
								   dataType:"json",
								   url: "/userControl/DELETE/cn.com.fig.dao.UserMapper.delete",
								   data: {priId:row.userId},
								   success: function(msg){
								     if(msg){
								    	 $.messager.alert('Warning',msg.retMsg);
								    	 $('#table-grid').datagrid('reload');
								     }
								   }
								});
						}
					});
				}
			},{
				text:'身份维护',
				iconCls:'icon-large-smartart',
				handler:function(){
					var tt = $('#table-grid');
					var row=tt.datagrid('getSelected');
					if(row){
						$("#identity-grid").datagrid({
							url:'/baseControl/GET/cn.com.fig.dao.UserIdentityMapper.list',
							queryParams:{
								userId:row.userId,
								needSplitPage:false
							},
							onLoadSuccess:function(data){
								cWindow = false;
								var rr = data.rows;
								$("#identity-grid").datagrid("unselectAll");
								for(var i=0;i<rr.length;i++){
									if(rr[i].userIdentiryId){
										$("#identity-grid").datagrid("selectRecord",rr[i].identityId);
									}
								}
								cWindow = true;
							},
							onCheck:function(rowIndex,rowData){
								if(!cWindow) 
									return;
								$('#userId_identity').textbox("setValue",row.userId);
								$('#userName_identity').textbox("setValue",row.userName);
								$('#identityId_identity').textbox("setValue",rowData.identityId);
								$('#identityName_identity').textbox("setValue",rowData.identityName);
								$.ajax({
									   type: "POST",
									   dataType:"text",
									   url: "/uuidGen/genUUID",
									   success: function(msg){
									     if(msg){
									    	 $('#userIdentiryId_identity').val(msg);
											 $("#identitySaveWindows").window('open');
									     }
									   }
									});
							},
							onUncheck:function(rowIndex,rowData){
								if(!cWindow) 
									return;
								if(rowData.userIdentiryId){
									$.messager.confirm('提示','您确定要删除吗？',function (r){
										if(r){
											$.ajax({
												   type: "POST",
												   dataType:"json",
												   url: "/baseControl/DELETE/cn.com.fig.dao.UserIdentityMapper.delete",
												   data: {priId:rowData.userIdentiryId},
												   success: function(msg){
												     if(msg){
												    	 $.messager.alert('Warning',msg.retMsg);
												    	 $("#identity-grid").datagrid('load',{
												    		 userId:row.userId,
															 needSplitPage:false
												    		 });
												     }
												   }
												});
										}
									});
								}
							}
						});
						
						$("#identityWindows").window('open');
					}else{
						$.messager.alert('Warning','请选择要编辑的行！');
					}
				}
			}];
	$(function(){
		$('#ff').form({
			url:"/baseControl/POST",
			onSubmit: function(){
				var isValid = $(this).form('validate');
				if (!isValid){
					$.messager.alert('Warning','请填写必填项');
				}
				return isValid;	
			},
			success:function(msg){
			     if(msg){
			    	 var data = eval('(' + msg + ')');
			    	 $.messager.alert('Warning',data.retMsg);
			    	 $('#table-grid').datagrid('reload');
			    	 $("#saveWindows").window('close');
			     }
			}
		});
		
		$('#identityForm').form({
			url:"/baseControl/POST",
			onSubmit: function(){
				var isValid = $(this).form('validate');
				if (!isValid){
					$.messager.alert('Warning','请填写必填项');
				}
				return isValid;	
			},
			success:function(msg){
			     if(msg){
			    	 var data = eval('(' + msg + ')');
			    	 $.messager.alert('Warning',data.retMsg);
			    	 $("#identity-grid").datagrid('reload');
			    	 $("#identitySaveWindows").window('close');
			     }
			}
		});
	});
	//用户表单提交方法
	function submitForm(){
		var insertMark = $('#insertMark').val();
		var reqUrl = ''
		if(insertMark == 0){
			reqUrl = '/userControl/POST/cn.com.fig.dao.UserMapper.update';
		}else{
			reqUrl = '/userControl/PUT/cn.com.fig.dao.UserMapper.insert';
		}
		
		$('#ff').form("submit",{
			url:reqUrl
		});	
	}
	//用户身份信息表单提交方法
	function identitySubmitForm(){
		var reqUrl = '/baseControl/PUT/cn.com.fig.dao.UserIdentityMapper.insert';
		$('#identityForm').form("submit",{
			url:reqUrl
		});	
	}
	</script>      
    </body>
</html>
